#! /bin/sh

. /lib/lsb/init-functions

#####################
#BEGIN CONFIG SECTION

#Location of daemon
prog=/usr/sbin/flashpolicytwistd.py

#Pid file to track start/stop of process
pidfile=/var/run/flashpolicytwistd

#Run as user
runasuser=nobody
runasgroup=nogroup

#END CONFIG SECTION
#####################

start() {
    echo "Starting flashpolicytwistd"
    twistd --logfile /dev/null --pidfile $pidfile --gid=$runasgroup --uid=$runasuser -y $prog && echo "flashpolicytwistd started" && exit 0
    echo "Failed to start flashpolicytwistd"
    exit 1
}

stop() {
    echo "Stopping flashpolicytwistd"
    killproc -p $pidfile "$prog"
    exit $?
}
    
case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    *)
    echo "Usage: flashpolicytwistd {start|stop}"
esac

exit 1
